/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//jQuery.getScript('./js/js_plantilla/scripts/jquery-ui.js');

var isUndefinedOrNull = function(obj) {
    return  (obj === null || obj === undefined || !obj);
};

var configurereportbuttons = function() {
    jQuery('.reportbutton').each(function() {
        configurereportbutton(this);
    });
};

var configurereportbutton = function(btn) {
    var configured = jQuery(btn).attr('configured');
    if (isUndefinedOrNull(configured)) {
        jQuery(btn).attr('configured', true);

        jQuery(btn).click(function(event) {
            event.preventDefault();

            var url = jQuery(this).attr('url');
            var args = jQuery(this).closest('form').serialize();
            if (!isUndefinedOrNull(url)) {
                jQuery.post(url, args, function(reportName) {
                    if (!isUndefinedOrNull(reportName)) {
                        window.open('./report/report/' + reportName);
                    }
                });
            }
        });
    }
};

jQuery(document).ready(function() {
    configurereportbuttons();
});